﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RuoVea.OmiApp.Template.Attributes;
using RuoVea.OmiApp.Template.Dto;
using RuoVea.ExDto;
using RuoVea.OmiApp.Template.Entitys;
using RuoVea.OmiApp.Template.Service;

namespace RuoVea.OmiApp.Template.Controllers;
/// <summary>
/// 
/// </summary>
[AppRoute]
public class DictTypController : Controller
{
    /// <summary>
    /// 
    /// </summary>
    private readonly ISysDictTypService _sysDictTypService;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sysDictTypService"></param>
    public DictTypController(ISysDictTypService sysDictTypService)
    {
        _sysDictTypService = sysDictTypService;
    }
    /// <summary>
    /// 参数配置页面
    /// </summary>
    [HttpGet("Index")]
    public IActionResult Index()
    {
        return View();
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("pages")]
    public async Task<RestfulResult<PageResult<SysDictTypeDto>>> GetPagesAsync(SysDictTypeParam data)
    {
        return await _sysDictTypService.GetPagesAsync(data);
    }

    /// <summary>
    /// 根据主键查询
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("data/{id:long}")]
    public async Task<RestfulResult<SysDictTypeDto>> GetDataAsync(long id)
    {
        return await _sysDictTypService.GetDataAsync(id);
    }

    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("submit")]
    public async Task<RestfulResult> SubmitAsync(SysDictTypeDto data)
    {
        if (data.Id == 0)
        {
            return await _sysDictTypService.AddDataAsync(data);
        }
        else
        {
            return await _sysDictTypService.UpdateDataAsync(data);
        }
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete("delete/{id:long}")]
    public async Task<RestfulResult> DeleteAsync(long id)
    {
        return await _sysDictTypService.DeleteDataAsync(id);
    }

    /// <summary>
    /// 获取字典类型下所有字典值
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [AllowAnonymous]
    [HttpGet("dicttypedropdown")]
    public async Task<RestfulResult<List<SysDictValue>>> GetDictTypeDropDown(DropDownDictTypeInput data)
    {
        return await _sysDictTypService.GetDictTypeDropDown(data);
    }

    /// <summary>
    /// 更新字典类型状态
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("changedicttypestatus")]
    public async Task<RestfulResult> ChangeDictTypeStatus(ChangeStateDictTypeInput data)
    {
        return await _sysDictTypService.ChangeDictTypeStatus(data);
    }
}
